// 用户状态
import { reqUserLogin } from '@/api/use'
export default {
  namespaced: true,
  state: () => {
    return {
      profile: {
        id: '',
        nickname: 'O(∩_∩)O哈哈~',
        token: ''
      }
    }
  },
  mutations: {
    setUserId (state, id) {
      state.profile.id = id
    },
    setProfile (state, newProfile) {
      state.profile = newProfile
    },
    clearProfile (state) {
      state.profile = {
        id: '',
        nickname: '',
        avatar: '',
        token: '',
        mobile: ''
      }
    }
  },
  actions: {
    async login (store, form) {
      const { result } = await reqUserLogin(form)
      store.commit('setProfile', result)
      // console.log(result)
    }

  }
}
